import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';

const buildTencentUploadData = (file: any, fallbackName: string) => {
  const name = file?.name || fallbackName;
  const extFromName = name?.includes('.') ? name.split('.').pop() : '';
  const mime = file?.type || '';
  const extFromMime = mime.includes('/') ? mime.split('/').pop() : '';
  const ext = (extFromName || extFromMime || 'jpg').toUpperCase();
  return {
    fileType: ext,
    fileName: name,
  };
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '姓名',
    align: "center",
    dataIndex: 'name',
    width: 100
  },
  {
    title: '电话',
    align: "center",
    dataIndex: 'phone'
  },
  {
    title: '邮箱',
    align: "center",
    dataIndex: 'email',
    width: 250
  },
  {
    title: '身份证',
    align: "center",
    dataIndex: 'idnumber',
    width: 200
  },
  {
    title: '地址',
    align: "center",
    dataIndex: 'address',
    width: 350
  },
  {
    title: '合同编号',
    align: "center",
    dataIndex: 'contractcode',
    width: 200
  },
  {
    title: '身份证正面',
    align: 'center',
    dataIndex: 'picture1',
    customRender: render.renderImage,
  },
  {
    title: '身份证反面',
    align: 'center',
    dataIndex: 'picture2',
    customRender: render.renderImage,
  },
  {
    title: '营业执照1',
    align: 'center',
    dataIndex: 'license1',
    customRender: render.renderImage,
  },
  {
    title: '营业执照2',
    align: 'center',
    dataIndex: 'license2',
    customRender: render.renderImage,
  },
  {
    title: 'licensepic1',
    align: 'center',
    dataIndex: 'licensepic1',
    defaultHidden: true,
  },
  {
    title: 'licensepic2',
    align: 'center',
    dataIndex: 'licensepic2',
    defaultHidden: true,
  },
  {
    title: '授权书',
    align: 'center',
    dataIndex: 'authorization1',
    customRender: render.renderImage,
  },
  {
    title: 'authorizationpic',
    align: 'center',
    dataIndex: 'authorizationpic',
    defaultHidden: true,
  },
  {
    title: '合作有效期',
    align: "center",
    dataIndex: 'duration'
  },
  {
    title: '合同模板',
    align: "center",
    dataIndex: 'templateid_dictText',
    width: 350
  },
  {
    title: '合同id',
    align: "center",
    dataIndex: 'contractid',
    defaultHidden: true
  },
  {
    title: '合同ID',
    align: "center",
    dataIndex: 'flowId',
    width: 300,
    
  },
  {
    title: '是否成功发起签署',
    align: "center",
    dataIndex: 'flowId',
    customRender: ({ text }) => {
      return text ? '是' : '否';
    }
  },

];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "姓名",
    field: 'name',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "电话",
    field: 'phone',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "身份证",
    field: 'idnumber',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "合同编号",
    field: 'contractcode',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "合作有效期",
    field: 'duration',
    component: 'Input',
    //colProps: {span: 6},
  },
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'name',
    component: 'Input',
  },
  {
    label: '电话',
    field: 'phone',
    component: 'Input',
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
  },
  {
    label: '身份证',
    field: 'idnumber',
    component: 'Input',
  },
  {
    label: '地址',
    field: 'address',
    component: 'Input',
  },
  {
    label: '合同编号',
    field: 'contractcode',
    component: 'Input',
  },
  {
    label: '身份证正面',
    field: 'picture1',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
      action: '/tencent_esign/upload/uploadFile',
      extraData: (file) => buildTencentUploadData(file, 'idcard_front.jpg'),
    },
  },
  {
    label: '身份证反面',
    field: 'picture2',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
      action: '/tencent_esign/upload/uploadFile',
      extraData: (file) => buildTencentUploadData(file, 'idcard_back.jpg'),
    },
  },
  {
    label: '营业执照1',
    field: 'license1',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
      action: '/tencent_esign/upload/uploadFile',
      extraData: (file) => buildTencentUploadData(file, 'license1.jpg'),
    },
  },
  {
    label: '营业执照2',
    field: 'license2',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
      action: '/tencent_esign/upload/uploadFile',
      extraData: (file) => buildTencentUploadData(file, 'license2.jpg'),
    },
  },
  {
    label: '授权书',
    field: 'authorization1',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
      action: '/tencent_esign/upload/uploadFile',
      extraData: (file) => buildTencentUploadData(file, 'authorization1.jpg'),
    },
  },
  {
    label: '',
    field: 'authorizationpic',
    component: 'Input',
    show: false,
  },
  {
    label: '合作有效期',
    field: 'duration',
    component: 'Input',
  },
  {
    label: '合同模板',
    field: 'templateid',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode: "esign_contracts,templatename,templateid"
    },
  },
  {
    label: '合同ID',
    field: 'flowId',
    component: 'Input',
    dynamicDisabled: true
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 发起签署表单数据
export const initiateSignFormSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'name',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入姓名!' },
      ];
    },
  },
  {
    label: '电话',
    field: 'phone',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入电话!' },
      ];
    },
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
  },
  {
    label: '身份证',
    field: 'idnumber',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入身份证!' },
      ];
    },
  },
  {
    label: '地址',
    field: 'address',
    component: 'Input',
  },
  {
    label: '合同编号',
    field: 'contractcode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入合同编号!' },
      ];
    },
  },
  {
    label: '合作有效期',
    field: 'duration',
    component: 'Input',
  },
  {
    label: '合同模板',
    field: 'templateid',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "esign_contracts,templatename,templateid"
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择合同模板!' },
      ];
    },
  },
  {
    label: '合同ID',
    field: 'flowId',
    component: 'Input',
    dynamicDisabled: true
  },
  // 主键隐藏字段
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: {title: '姓名',order: 0,view: 'text', type: 'string',},
  phone: {title: '电话',order: 1,view: 'text', type: 'string',},
  email: {title: '邮箱',order: 2,view: 'text', type: 'string',},
  idnumber: {title: '身份证',order: 3,view: 'text', type: 'string',},
  contractcode: {title: '合同编号',order: 4,view: 'text', type: 'string',},
  duration: {title: '合作有效期',order: 5,view: 'text', type: 'string',},
  templateid: {title: '合同模板',order: 6,view: 'list', type: 'string',dictTable: "esign_contracts", dictCode: 'templateid', dictText: 'templatename',},
  contractid: {title: '合同id',order: 7,view: 'text', type: 'string',},
  flowId: {title: '合同ID',order: 8,view: 'text', type: 'string',},
  signStatus: {title: '是否成功发起签署',order: 9,view: 'text', type: 'string',},
  address: {title: '地址',order: 10,view: 'text', type: 'string',},
};
